package cn.xgj.sfzy.service.impl;

import cn.xgj.sfzy.entity.Course;
import cn.xgj.sfzy.entity.CourseCollect;
import cn.xgj.sfzy.mapper.CourseCollectMapper;
import cn.xgj.sfzy.mapper.CourseMapper;
import cn.xgj.sfzy.service.CourseCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CourseCollect
 * @Description TODO
 * @Author gcc
 * @Date 2024年10月31日 19:32
 * @Version 1.0
 */
@Service
public class CourseCollectImpl implements CourseCollectService {
    @Autowired
    private CourseCollectMapper courseCollectMapper;
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<CourseCollect> findByUserId(Long userId) {
        List<CourseCollect> courseCollectList = courseCollectMapper.findByUserId(userId);
        for (CourseCollect courseCollect : courseCollectList) {
            if (courseCollect.getCollectId()==null){
                return courseCollectList;
            }
            Long courseId = courseCollect.getCourseId();
            Course course = courseMapper.findById(Math.toIntExact(courseId));
            courseCollect.setCourse(course);
        }
        return courseCollectList;
    }
}
